﻿Imports System.Collections.Specialized

Public Class Budget

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click

        Me.Close()

    End Sub

    Private Function CreateDataSourceSong() As DataTable
        Dim dt As New DataTable
        Dim dc As DataColumn
        dc = dt.Columns.Add("预算日期")
        dc.DefaultValue = ""
        dc = dt.Columns.Add("分类1")
        dc.DefaultValue = ""
        dc = dt.Columns.Add("分类2")
        dc.DefaultValue = ""
        dc = dt.Columns.Add("金额", GetType(Decimal))
        dc.DefaultValue = 0
        dc = dt.Columns.Add("备注")
        dc.DefaultValue = ""
        dc = dt.Columns.Add("用户")
        dc.DefaultValue = ""
        dc = dt.Columns.Add("月合计行", GetType(Integer))
        dc.DefaultValue = 0

        If chk按用户.Checked Then
            For Year As Integer = dt月别开始时间.Value.Year To dt月别结束时间.Value.Year

                Dim 开始月 As Integer = 1
                Dim 结束月 As Integer = 12
                If Year = dt月别开始时间.Value.Year Then
                    开始月 = dt月别开始时间.Value.Month
                End If
                If Year = dt月别结束时间.Value.Year Then
                    结束月 = dt月别结束时间.Value.Month
                End If

                For endmouth As Integer = 开始月 To 结束月
                    Dim dt支出类型 As DataTable = ct.FillTable("select * from XscBugType where ParentID=179 ")
                    For Each dr2 As DataRow In dt支出类型.Rows

                        Dim sb As New Text.StringBuilder
                        sb.AppendLine("select budgetOut.*,WysInputUser.UserName name  from budgetOut ")
                        sb.AppendLine(" LEFT JOIN WysInputUser ")
                        sb.AppendLine(" ON budgetOut.username=WysInputUser.id ")
                        sb.AppendLine(" where budgetOut.TYPE= '" & CStr(dr2("id")) & "' AND budgetOut.YEAR=" & CStr(Year) & " AND budgetOut.MONTH=" & CStr(endmouth))
                        If (_ParamsValues.Contains("用户")) Then
                            sb.AppendLine(" AND budgetOut.UserName ='" & _ParamsValues.Item("用户").ToString & "'")
                        End If
                        '先查询大分类里面是否包含
                        Dim dt内容1 As DataTable = ct.FillTable(sb.ToString)
                        If dt内容1.Rows.Count > 0 Then
                            For Each dr4 As DataRow In dt内容1.Rows
                                Dim dr As DataRow = dt.NewRow
                                dr("预算日期") = Year & "年" & endmouth & "月"
                                dr("分类1") = dr2("name")
                                dr("分类2") = dr2("name")
                                dr("金额") = CDec(dr4("count"))
                                dr("备注") = dr4("memo")
                                dr("用户") = dr4("name")
                                dt.Rows.Add(dr)
                            Next
                        End If

                        '再查小分类
                        Dim dt支出类型1 As DataTable = ct.FillTable("select * from XscBugType where ParentID= " & CStr(dr2("id")))
                        If dt支出类型1.Rows.Count > 0 Then
                            For Each dr3 As DataRow In dt支出类型1.Rows
                                sb.Length = 0
                                sb.AppendLine("select budgetOut.*,WysInputUser.UserName name  from budgetOut ")
                                sb.AppendLine(" LEFT JOIN WysInputUser ")
                                sb.AppendLine(" ON budgetOut.username=WysInputUser.id ")
                                sb.AppendLine(" where budgetOut.TYPE= '" & CStr(dr3("id")) & "' AND budgetOut.YEAR=" & CStr(Year) & " AND budgetOut.MONTH=" & CStr(endmouth))
                                If (_ParamsValues.Contains("用户")) Then
                                    sb.AppendLine(" AND budgetOut.UserName ='" & _ParamsValues.Item("用户").ToString & "'")
                                End If
                                dt内容1 = ct.FillTable(sb.ToString)
                                Dim 合计2 As Decimal = 0
                                If dt内容1.Rows.Count > 0 Then
                                    For Each dr4 As DataRow In dt内容1.Rows
                                        Dim dr As DataRow = dt.NewRow
                                        dr("预算日期") = Year & "年" & endmouth & "月"
                                        dr("分类1") = dr2("name")
                                        dr("分类2") = dr3("name")
                                        dr("金额") = CDec(dr4("count"))
                                        dr("备注") = dr4("memo")
                                        dr("用户") = dr4("name")
                                        dt.Rows.Add(dr)
                                    Next
                                End If
                            Next
                        End If
                    Next
                    ''开始计算月合计
                    'Dim 合计金额 As Decimal = If(dt.Compute("sum(金额)", "月合计行= 0 and 预算日期 ='" & Year & "年" & endmouth & "月" & "'") Is DBNull.Value, 0, dt.Compute("sum(金额)", "月合计行= 0 and 预算日期 ='" & Year & "年" & endmouth & "月" & "'"))
                    'If 合计金额 > 0 Then
                    '    Dim dr As DataRow = dt.NewRow
                    '    dr("分类2") = "月合计金额"
                    '    dr("金额") = 合计金额
                    '    dr("月合计行") = 1
                    '    dt.Rows.Add(dr)
                    'End If
                Next
            Next
        Else
            For Year As Integer = dt月别开始时间.Value.Year To dt月别结束时间.Value.Year

                Dim 开始月 As Integer = 1
                Dim 结束月 As Integer = 12
                If Year = dt月别开始时间.Value.Year Then
                    开始月 = dt月别开始时间.Value.Month
                End If
                If Year = dt月别结束时间.Value.Year Then
                    结束月 = dt月别结束时间.Value.Month
                End If

                For endmouth As Integer = 开始月 To 结束月
                    Dim dt支出类型 As DataTable = ct.FillTable("select * from XscBugType where ParentID=179 ")
                    For Each dr2 As DataRow In dt支出类型.Rows

                        Dim sb As New Text.StringBuilder
                        sb.AppendLine("select budgetOut.*,WysInputUser.UserName name  from budgetOut ")
                        sb.AppendLine(" LEFT JOIN WysInputUser ")
                        sb.AppendLine(" ON budgetOut.username=WysInputUser.id ")
                        sb.AppendLine(" where budgetOut.TYPE= '" & CStr(dr2("id")) & "' AND budgetOut.YEAR=" & CStr(Year) & " AND budgetOut.MONTH=" & CStr(endmouth))
                        If (_ParamsValues.Contains("用户")) Then
                            sb.AppendLine(" AND budgetOut.UserName ='" & _ParamsValues.Item("用户").ToString & "'")
                        End If
                        '先查询大分类里面是否包含
                        Dim dt内容1 As DataTable = ct.FillTable(sb.ToString)
                        If dt内容1.Rows.Count > 0 Then
                            For Each dr4 As DataRow In dt内容1.Rows
                                Dim dr As DataRow = dt.NewRow
                                dr("预算日期") = Year & "年" & endmouth & "月"
                                dr("分类1") = dr2("name")
                                dr("分类2") = dr2("name")
                                dr("金额") = CDec(dr4("count"))
                                dr("备注") = dr4("memo")
                                dr("用户") = dr4("name")
                                dt.Rows.Add(dr)
                            Next
                        End If

                        '再查小分类
                        Dim dt支出类型1 As DataTable = ct.FillTable("select * from XscBugType where ParentID= " & CStr(dr2("id")))
                        If dt支出类型1.Rows.Count > 0 Then
                            For Each dr3 As DataRow In dt支出类型1.Rows
                                sb.Length = 0
                                sb.AppendLine("select budgetOut.*,WysInputUser.UserName name  from budgetOut ")
                                sb.AppendLine(" LEFT JOIN WysInputUser ")
                                sb.AppendLine(" ON budgetOut.username=WysInputUser.id ")
                                sb.AppendLine(" where budgetOut.TYPE= '" & CStr(dr3("id")) & "' AND budgetOut.YEAR=" & CStr(Year) & " AND budgetOut.MONTH=" & CStr(endmouth))
                                If (_ParamsValues.Contains("用户")) Then
                                    sb.AppendLine(" AND budgetOut.UserName ='" & _ParamsValues.Item("用户").ToString & "'")
                                End If
                                dt内容1 = ct.FillTable(sb.ToString)
                                Dim 合计2 As Decimal = 0
                                If dt内容1.Rows.Count > 0 Then
                                    For Each dr4 As DataRow In dt内容1.Rows
                                        Dim dr As DataRow = dt.NewRow
                                        dr("预算日期") = Year & "年" & endmouth & "月"
                                        dr("分类1") = dr2("name")
                                        dr("分类2") = dr3("name")
                                        dr("金额") = CDec(dr4("count"))
                                        dr("备注") = dr4("memo")
                                        dr("用户") = dr4("name")
                                        dt.Rows.Add(dr)
                                    Next
                                End If
                            Next
                        End If
                    Next
                    '开始计算月合计
                    Dim 合计金额 As Decimal = If(dt.Compute("sum(金额)", "月合计行= 0 and 预算日期 ='" & Year & "年" & endmouth & "月" & "'") Is DBNull.Value, 0, dt.Compute("sum(金额)", "月合计行= 0 and 预算日期 ='" & Year & "年" & endmouth & "月" & "'"))
                    If 合计金额 > 0 Then
                        Dim dr As DataRow = dt.NewRow
                        dr("分类2") = "月合计金额"
                        dr("金额") = 合计金额
                        dr("月合计行") = 1
                        dt.Rows.Add(dr)
                    End If
                Next
            Next

            '开始计算总合计（月合计的金额）
            If dt.Rows.Count > 0 Then
                Dim 合计金额 As Decimal = dt.Compute("sum(金额)", "月合计行=1")
                Dim dr As DataRow = dt.NewRow
                dr("分类2") = "总合计金额"
                dr("金额") = 合计金额
                dt.Rows.Add(dr)
            End If

        End If

        Return dt

    End Function

    Private Sub PrintProcess(ByVal content As String)
        lbl1000.Text = content
        System.Windows.Forms.Application.DoEvents()
    End Sub

    Private _ParamsValues As New Hashtable
    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click

        _ParamsValues.Clear()

        Dim date3 As Date = New Date(dt月别开始时间.Value.Year, dt月别开始时间.Value.Month, 1)
        Dim date4 As Date = New Date(dt月别结束时间.Value.Year, dt月别结束时间.Value.Month, 1)

        If date3 > date4 Then
            ShowMessageBox("开始时间不能大于结束时间")
            dt月别开始时间.Focus()
            Exit Sub
        End If

        Dim date1 As New Date(Me.dt月别开始时间.Value.Year, Me.dt月别开始时间.Value.Month, Me.dt月别开始时间.Value.Day)
        Dim date2 As New Date(Me.dt月别结束时间.Value.Year, Me.dt月别结束时间.Value.Month, Me.dt月别结束时间.Value.Day)
        _ParamsValues.Add("开始时间", date1.ToString)
        _ParamsValues.Add("结束时间", date2.ToString)

        If Me.txtUsername.Text.Trim <> "" AndAlso Me.CheckBox1.Checked Then
            _ParamsValues.Add("用户", CStr(Me.txtUsername.Tag))
        End If

        Dim dt As System.Data.DataTable = CreateDataSourceSong()
        If dt.Rows.Count = 0 Then
            ShowMessageBox("没有数据")
            Exit Sub
        End If

        Try

            Dim englishFolder As String = System.IO.Path.Combine(GetCurrentDirectory, "Report")
            If Not System.IO.Directory.Exists(englishFolder) Then
                System.IO.Directory.CreateDirectory(englishFolder)
            End If

            Dim englishPath As String = System.IO.Path.Combine(englishFolder, "Budget.xls")
            Dim bCreate As Boolean = True
            If System.IO.File.Exists(englishPath) Then
                System.IO.File.Delete(englishPath)
            End If

            If rad明细.Checked Then
                If chk按用户.Checked Then

                    Dim englishCreate As New Budget_User(englishPath)
                    englishCreate.报表记录条数字 = Me.报表记录条数字
                    englishCreate.报表字体 = Me.报表字体
                    AddHandler englishCreate.PrintProcess, AddressOf PrintProcess

                    Dim dtUser As DataTable = ct.FillTable("select * from WysInputUser where type=0 order by userindex")

                    If (_ParamsValues.Contains("用户")) Then
                        dtUser = ct.FillTable("select * from WysInputUser where type=0 and id ='" & _ParamsValues.Item("用户").ToString & "'")
                    End If

                    Dim 合计金额 As Decimal = 0
                    Dim realindex As Integer = 1
                    Dim newTable As DataTable = dt.Clone
                    Dim dv As DataView = dt.DefaultView

                    If dtUser.Rows.Count > 0 Then
                        For index As Integer = 0 To dtUser.Rows.Count - 1
                            dv.RowFilter = "用户='" + CStr(dtUser.Rows(index)("username")) + "'"
                            newTable = dv.ToTable
                            If newTable.Rows.Count > 0 Then

                                '计算月合计
                                Dim newTableA As DataTable = newTable.Clone
                                Dim newTableB As DataTable = newTable.DefaultView.ToTable(True, "预算日期")
                                For kdex As Integer = 0 To newTableB.Rows.Count - 1
                                    合计金额 = 0
                                    Dim drs() As DataRow = newTable.Select("预算日期='" & newTableB.Rows(kdex)("预算日期").ToString & "'")
                                    For hdex As Integer = 0 To drs.Length - 1
                                        newTableA.ImportRow(drs(hdex))
                                        合计金额 += CDec(drs(hdex)("金额"))
                                    Next
                                    If 合计金额 > 0 Then
                                        Dim dr As DataRow = newTableA.NewRow
                                        dr("分类2") = "月合计金额"
                                        dr("金额") = 合计金额
                                        dr("月合计行") = 1
                                        newTableA.Rows.Add(dr)
                                    End If
                                Next

                                '开始计算总合计（月合计的金额）
                                If newTableA.Rows.Count > 0 Then
                                    合计金额 = newTableA.Compute("sum(金额)", "月合计行=1")
                                    Dim dr As DataRow = newTableA.NewRow
                                    dr("分类2") = "总合计金额"
                                    dr("金额") = 合计金额
                                    newTableA.Rows.Add(dr)
                                End If

                                For jndex As Integer = 0 To newTableA.Rows.Count - 2
                                    For kdex As Integer = jndex + 1 To newTableA.Rows.Count - 1
                                        If newTableA.Rows(jndex)("预算日期") = newTableA.Rows(kdex)("预算日期") Then
                                            newTableA.Rows(kdex)("预算日期") = ""
                                        End If
                                    Next
                                Next

                                englishCreate.DoOutData(newTableA, realindex, False)

                                realindex = realindex + 1
                            End If
                        Next

                        '开始出总合计
                        ' 预算日期	预算分类 预算分类 
                        Dim condition As String = ""
                        合计金额 = 0
                        Dim newTableG As DataTable = dt.Clone

                        Dim newTableD As DataTable = dt.DefaultView.ToTable(True, "预算日期")
                        For udex As Integer = 0 To newTableD.Rows.Count - 1
                            dv.RowFilter = "预算日期='" & newTableD.Rows(udex)("预算日期").ToString & "'"
                            Dim newTableE As DataTable = dv.ToTable
                            Dim newTableF As DataTable = newTableE.DefaultView.ToTable(True, "分类1", "分类2")
                            For vdex As Integer = 0 To newTableF.Rows.Count - 1
                                condition = "预算日期='" & newTableD.Rows(udex)("预算日期").ToString & "' AND 分类1='" & newTableF.Rows(vdex)("分类1").ToString & "' AND 分类2='" & newTableF.Rows(vdex)("分类2").ToString & "'"
                                合计金额 = dt.Compute("sum(金额)", condition)
                                If 合计金额 > 0 Then
                                    Dim drG As DataRow = newTableG.NewRow
                                    drG("预算日期") = newTableD.Rows(udex)("预算日期").ToString
                                    drG("分类1") = newTableF.Rows(vdex)("分类1").ToString
                                    drG("分类2") = newTableF.Rows(vdex)("分类2").ToString
                                    drG("用户") = "合计"
                                    drG("金额") = 合计金额
                                    newTableG.Rows.Add(drG)
                                End If
                            Next

                            合计金额 = newTableG.Compute("sum(金额)", "预算日期='" & newTableD.Rows(udex)("预算日期").ToString & "'")
                            Dim dr As DataRow = newTableG.NewRow
                            dr("分类2") = "月合计金额"
                            dr("金额") = 合计金额
                            dr("月合计行") = 1
                            dr("用户") = "合计"
                            newTableG.Rows.Add(dr)

                        Next

                        If newTableG.Rows.Count > 0 Then
                            合计金额 = newTableG.Compute("sum(金额)", "月合计行=1")
                            Dim dr As DataRow = newTableG.NewRow
                            dr("分类2") = "总合计金额"
                            dr("金额") = 合计金额
                            dr("用户") = "合计"
                            newTableG.Rows.Add(dr)
                        End If

                        For jndex As Integer = 0 To newTableG.Rows.Count - 2
                            For kdex As Integer = jndex + 1 To newTableG.Rows.Count - 1
                                If newTableG.Rows(jndex)("预算日期") = newTableG.Rows(kdex)("预算日期") Then
                                    newTableG.Rows(kdex)("预算日期") = ""
                                End If
                            Next
                        Next

                        englishCreate.DoOutData(newTableG, realindex, True)
                    End If
                    RemoveHandler englishCreate.PrintProcess, AddressOf PrintProcess
                Else
                    Dim englishCreate As New BudgetD(englishPath)
                    englishCreate.报表记录条数字 = Me.报表记录条数字
                    englishCreate.报表字体 = Me.报表字体

                    AddHandler englishCreate.PrintProcess, AddressOf PrintProcess

                    For jndex As Integer = 0 To dt.Rows.Count - 2
                        For kdex As Integer = jndex + 1 To dt.Rows.Count - 1
                            If dt.Rows(jndex)("预算日期") = dt.Rows(kdex)("预算日期") Then
                                dt.Rows(kdex)("预算日期") = ""
                            End If
                        Next
                    Next

                    englishCreate.DoOutData(dt)
                    RemoveHandler englishCreate.PrintProcess, AddressOf PrintProcess
                End If

            ElseIf rad统计.Checked Then
                If chk按用户.Checked Then

                    Dim englishCreate As New Budget_UserA(englishPath)
                    englishCreate.报表记录条数字 = Me.报表记录条数字
                    englishCreate.报表字体 = Me.报表字体
                    AddHandler englishCreate.PrintProcess, AddressOf PrintProcess

                    Dim dtUser As DataTable = ct.FillTable("select * from WysInputUser where type=0 order by userindex")

                    If (_ParamsValues.Contains("用户")) Then
                        dtUser = ct.FillTable("select * from WysInputUser where type=0 and id ='" & _ParamsValues.Item("用户").ToString & "'")
                    End If

                    Dim 合计金额 As Decimal = 0
                    Dim realindex As Integer = 1
                    Dim newTable As DataTable = dt.Clone
                    Dim dv As DataView = dt.DefaultView
                    Dim dr As DataRow

                    If dtUser.Rows.Count > 0 Then
                        For index As Integer = 0 To dtUser.Rows.Count - 1
                            dv.RowFilter = "用户='" + CStr(dtUser.Rows(index)("username")) + "'"
                            newTable = dv.ToTable
                            If newTable.Rows.Count > 0 Then

                                '计算月合计
                                Dim newTableA As DataTable = newTable.Clone
                                Dim newTableB As DataTable = newTable.DefaultView.ToTable(True, "预算日期")
                                For kdex As Integer = 0 To newTableB.Rows.Count - 1
                                    合计金额 = newTable.Compute("sum(金额)", "预算日期='" & newTableB.Rows(kdex)("预算日期").ToString & "'")
                                    dr = newTableA.NewRow
                                    dr("预算日期") = newTableB.Rows(kdex)("预算日期")
                                    dr("金额") = If(合计金额 = Nothing, 0, 合计金额)
                                    dr("用户") = CStr(dtUser.Rows(index)("username"))
                                    newTableA.Rows.Add(dr)
                                Next

                                '开始计算总合计（月合计的金额）
                                If newTableA.Rows.Count > 0 Then
                                    合计金额 = newTableA.Compute("sum(金额)", "")
                                    dr = newTableA.NewRow
                                    dr("金额") = If(合计金额 = Nothing, 0, 合计金额)
                                    dr("用户") = CStr(dtUser.Rows(index)("username"))
                                    newTableA.Rows.Add(dr)
                                End If

                                englishCreate.DoOutData(newTableA, realindex, False)

                                realindex = realindex + 1
                            End If
                        Next

                        '开始出总合计
                        ' 预算日期	预算分类 预算分类 
                        Dim condition As String = ""
                        合计金额 = 0
                        Dim newTableG As DataTable = dt.Clone

                        Dim newTableD As DataTable = dt.DefaultView.ToTable(True, "预算日期")
                        For udex As Integer = 0 To newTableD.Rows.Count - 1

                            合计金额 = dt.Compute("sum(金额)", "预算日期='" & newTableD.Rows(udex)("预算日期").ToString & "'")
                            dr = newTableG.NewRow
                            dr("预算日期") = newTableD.Rows(udex)("预算日期")
                            dr("金额") = If(合计金额 = Nothing, 0, 合计金额)
                            dr("用户") = "合计"
                            newTableG.Rows.Add(dr)
                        Next

                        合计金额 = newTableG.Compute("sum(金额)", "")
                        dr = newTableG.NewRow
                        dr("金额") = If(合计金额 = Nothing, 0, 合计金额)
                        dr("用户") = "合计"
                        newTableG.Rows.Add(dr)
                        englishCreate.DoOutData(newTableG, realindex, False)

                        '开始打印趋势图 
                        englishCreate.DoOutDataA(newTableG, realindex, True)

                    End If
                    RemoveHandler englishCreate.PrintProcess, AddressOf PrintProcess
                End If
                ElseIf rad执行情况.Checked Then

                End If

                '打开文件
                Using pro As New Process
                    pro.StartInfo.FileName = englishPath
                    pro.Start()
                End Using

        Catch ex As Exception
            ShowMessageBox(ex.ToString)
        End Try

    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If Me.CheckBox1.Checked Then
            Me.txtUsername.Enabled = True
            Me.btnUsername.Enabled = True
        Else
            txtUsername.Text = ""
            Me.txtUsername.Enabled = False
            Me.btnUsername.Enabled = False
        End If
    End Sub

    Private Sub btnUsername_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUsername.Click
        Using frm As wys.Control.Vb.ListForm = New wys.Control.Vb.ListForm
            frm.strName = Me.strName
            frm.iType = Me.iType
            frm.SQL = "select ID,UserName as 名称 from WysInputUser where type=0 order by userindex"
            Dim 显示列 As New StringCollection
            显示列.Add("名称")
            frm.Width = 100
            frm.Height = 200
            frm.显示列 = 显示列
            frm.ShowDialog()
            If frm.返回值.Count > 0 Then
                txtUsername.Tag = CStr(frm.返回值(0))
                txtUsername.Text = CStr(frm.返回值(1))
            End If
        End Using
    End Sub

#Region "窗体数据保存的重载方法 A-2010-09-06"
    Public Overrides Sub 保存窗体数据到数据库(ByRef dtData As System.Data.DataTable)

        dtData.Rows.Add(New Object() {"开始时间.年", "", dt月别开始时间.Value.Year.ToString})
        dtData.Rows.Add(New Object() {"开始时间.月", "", dt月别开始时间.Value.Month.ToString})
        dtData.Rows.Add(New Object() {"开始时间.日", "", dt月别开始时间.Value.Day.ToString})

        dtData.Rows.Add(New Object() {"结束时间.年", "", dt月别结束时间.Value.Year.ToString})
        dtData.Rows.Add(New Object() {"结束时间.月", "", dt月别结束时间.Value.Month.ToString})
        dtData.Rows.Add(New Object() {"结束时间.日", "", dt月别结束时间.Value.Day.ToString})

        If rad明细.Checked Then
            dtData.Rows.Add(New Object() {"分类1", "", "明细"})
        ElseIf rad统计.Checked Then
            dtData.Rows.Add(New Object() {"分类1", "", "统计"})
        ElseIf rad执行情况.Checked Then
            dtData.Rows.Add(New Object() {"分类1", "", "执行情况"})
        End If

    End Sub

    Public Overrides Sub 存取数据库数据到窗体(ByVal dtDbData As System.Data.DataTable)
        If dtDbData.Rows.Count > 0 Then

            Select Case 查找数据("分类1", "", "明细", dtDbData)
                Case "明细"
                    rad明细.Checked = True
                Case "统计"
                    rad统计.Checked = True
                Case "执行情况"
                    rad执行情况.Checked = True
                Case Else
                    rad明细.Checked = True
            End Select
         
            Dim date1 As New Date(CInt(查找数据("开始时间.年", "", Me.dt月别开始时间.Value.Year.ToString, dtDbData)), CInt(查找数据("开始时间.月", "", "1", dtDbData)), CInt(查找数据("开始时间.日", "", "1", dtDbData)))
            Me.dt月别开始时间.Value = date1
            date1 = New Date(CInt(查找数据("结束时间.年", "", Me.dt月别开始时间.Value.Year.ToString, dtDbData)), CInt(查找数据("结束时间.月", "", "1", dtDbData)), CInt(查找数据("结束时间.日", "", "1", dtDbData)))
            Me.dt月别结束时间.Value = date1

        End If

    End Sub

#End Region

End Class
